package chat.utils;

import com.tencentyun.TLSSigAPIv2;
import top.revery.api.util.ImConfig;

import java.util.Map;

/**
 * @author denghao
 * @title   工具
 * @package
 * @date 2019/12/31 21:25
 */
public class TencentIMHelper {

    public static String createString(Map<String,Object> map){
        StringBuffer sb = new StringBuffer();
        for (Map.Entry<String, Object> m : map.entrySet()) {
            if ("".equals(m.getValue()) || null == m.getValue()) {
                continue;
            }
            sb.append(m.getKey()).append("=").append(m.getValue()).append("&");
        }

        return sb.toString().substring(0,sb.toString().length()-1);

    }

    public static String getUsig(String identifier){
        TLSSigAPIv2 api = new TLSSigAPIv2(ImConfig.TENCENT_SDKAPPID,ImConfig.secretKey);
        return api.genSig(identifier,180*86400);

    }

    public static String createNotify(Map<String, Object> map) {
        StringBuffer sb = new StringBuffer();
        for (Map.Entry<String, Object> m : map.entrySet()) {
            if ("".equals(m.getValue()) || null == m.getValue()) {
                continue;
            }
            sb.append(m.getKey()).append("=$").append(m.getValue()).append("&");
        }

        return sb.toString().substring(0,sb.toString().length()-1);

    }
}
